<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8">
    <title>用户列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="resources/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="resources/css/public.css" media="all" />
</head>
<body class="childrenBody">
<form class="layui-form">
    <blockquote class="layui-elem-quote quoteBox">
        <form class="layui-form">
            <div class="layui-inline">
                <div class="layui-input-inline">
                    <input type="text" class="layui-input searchVal" placeholder="请输入搜索的内容" />
                </div>
                <a class="layui-btn search_btn" data-type="reload">搜索</a>
            </div>
<!--            <div class="layui-inline">-->
<!--                <a class="layui-btn layui-btn-normal addUsers_btn">添加用户</a>-->
<!--            </div>-->
<!--            <div class="layui-inline">-->
<!--                <a class="layui-btn layui-btn-danger layui-btn-normal delAll_btn">批量删除</a>-->
<!--            </div>-->
        </form>
    </blockquote>
    <table id="productList" lay-filter="productListFilter"></table>

    <!--操作-->
    <script type="text/html" id="productListBar">
        <a class="layui-btn layui-btn-xs" lay-event="look">查看</a>
        <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del">删除</a>
    </script>
</form>
<script type="text/javascript" src="resources/layui/layui.js"></script>
<script th:inline="none">
    layui.use(['form','layer','laydate','table','laytpl'],function(){
        var form = layui.form,
            layer = parent.layer === undefined ? layui.layer : top.layer,
            $ = layui.jquery,
            laydate = layui.laydate,
            laytpl = layui.laytpl,
            table = layui.table;
        //商品列表
        var tableIns = table.render({
            elem: '#productList',
            url : 'product/productAll',
            page : true,
            height : "full-125",
            limit : 20,
            limits : [10,15,20,25],
            id : "productListTable",
            cols : [[
                // {type: "checkbox", fixed:"left"},
                {field: 'name', title: '商品名称',align:"center"},
                {field: 'price', title: '价格（￥）',align:"center"},
                {field: 'state', title: '商品详情', align:"center"},
                {field: 'status', title: '状态',align:"center",templet:function (row) {
                        if(row.status==1){return "已被购买"}
                        else if (row.status==0){return "暂无购买"}
                        else if (row.status==3){return "没有通过审核"}
                    }},
                {title: '操作', width:250, templet:'#productListBar',fixed:"right",align:"center"}
            ]]
        });

        $(".search_btn").on("click",function(){
            table.reload("productListTable",{

                page: {
                    curr: 1 //重新从第 1 页开始
                },
                where: {
                    name: $(".searchVal").val()  //搜索的关键字
                }
            })
        });
        //点击的操作
        table.on("tool(productListFilter)",function (obj) {
            console.log(obj)
            //获取当前行的数据
            var data=obj.data;
            switch (obj.event){
                case 'look':
                    lookProduct(data);
                    break;
                case 'del':
                    deleteProduct(data);
                    break;

            }
        });
        //进入商品详情页面
        function lookProduct(data){
            var index=layui.layer.open({
                title:"查看二手商品详情",
                type:2,
                area:['500px','500px'],
                content:"tolookProduct.do",
                success:function (layero,index) {
                    var body = layui.layer.getChildFrame('body', index);//少了这个是不能从父页面向子页面传值的
                    body.contents().find(".name").val(data.name);
                    body.contents().find(".price").val(data.price);
                    body.contents().find(".state").val(data.state);
                    body.contents().find(".time").val(data.createTime);
                    body.contents().find(".pic").val(data.mImgs);
                }
            });
        }
        //删除
        function deleteProduct(data){
            $.ajax({
                url:"product/deleteProduct/"+data.productSn,
                type:"DELETE",
                success:function (res) {
                    if(res.code==200){
                        layer.msg(res.msg);
                        tableIns.reload();//重新刷新表格
                    }
                }
            });
        }




    })

</script>
</body>
</html>